#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

Import('BuildEnv')
import sys
import platform

def MapBuildDir(list):
    return map(lambda x: '#/' + Dir('.').path + '/../../' + x, list)

env = BuildEnv.Clone()

env.Append(CCFLAGS = '-fPIC')

libhttpc = env.Library('httpc', ['http_client.cc', 'http_curl.cc'])

libvncapi = env.Library('vncapi', ['vncapi.cc'])
env.Prepend(LIBS = ['sandesh', 'curl', 'io'])

libs = MapBuildDir(['io'])
env.Append(LIBPATH = libs)

httpc_include = env['TOP_INCLUDE']
env.Prepend(CPPPATH = httpc_include)

env.Append(LIBPATH = [
    '#/' + Dir('..').path,
    '../../debug/httpc',
    '../../debug/curl'
])

env.Append(LIBS = [
    'task_test', 'gunit', 'base', 'httpc', 'sandesh', 'http',
    'http_parser', 'process_info', 'curl', 'io',
    'sandeshvns', 'base', 'pugixml'
])

if sys.platform != 'darwin':
    env.Append(LIBS = ['rt'])

httpcd = env.Program(target = 'httpcd',
                   source = ['main.cc'])
env.Requires(httpcd, '#/build/include/curl/curl.h')
env.AppendUnique(LINKFLAGS = '-Wl,--no-as-needed')
env.Append(LIBS = ['vncapi', 'ssl', 'crypto', 'json-c', 'httpc'])
vncapitest = env.Program(target = 'vncapitest', source = ['vncapi_test.cc'])
env.Requires(libvncapi, '#/build/include/curl/curl.h')
env.Requires(libvncapi, '#/build/include/rapidjson.h')
env.Requires(vncapitest, '#/build/include/rapidjson.h')
#env.SConscript('test/SConscript', exports='BuildEnv', duplicate = 0)
env.Install(env['TOP_LIB'], libhttpc)
env.Install(env['TOP_LIB'], libvncapi)
